package edu.up.firesawakening;

/**
 * This class provides methods to generate maps for the game to use
 * 
 * @author Matt Delaney
 * @author Viet Phan
 * @version 19 November 2012
 */
public abstract class TacticsMapFactory {

	/**
	 * Creates a basic two-player map. 8x8 grid. Two units per player, and each
	 * player has a castle.
	 * 
	 * @return Map #1. DEPRECIATED. DO NOT USE. BAD THINGS WILL HAPPEN.
	 */
	@Deprecated
	public static Tile[][] createMap1() {
		Tile[][] buildMap = new Tile[8][8];
		// create a basic map outline
		for (int i = 0; i < 8; i++)
			for (int j = 0; j < 8; j++)
				buildMap[i][j] = new Tile(Tile.TileType.PLAINS, i, j);

		// create interesting terrain
		buildMap[3][5] = new Tile(Tile.TileType.MOUNTAIN, 3, 5);
		buildMap[5][2] = new Tile(Tile.TileType.MOUNTAIN, 5, 2);

		// create player 0's units
		buildMap[1][1].setUnit(new Castle(0));
		buildMap[2][1].setUnit(new MeleeUnit(10, 1, 0, 2, 1, 0));
		buildMap[1][2].setUnit(new MeleeUnit(10, 1, 0, 2, 1, 0));

		// create player 1's units
		buildMap[6][6].setUnit(new Castle(1));
		buildMap[6][5].setUnit(new MeleeUnit(10, 1, 0, 2, 1, 1));
		buildMap[5][6].setUnit(new MeleeUnit(10, 1, 0, 2, 1, 1));

		return buildMap;
	}

	/**
	 * A bigger, 16x16 test map
	 * 
	 * @return Map #1
	 */
	public static Tile[][] createBigMap() {
		int xSize = 16;
		int ySize = 16;

		Tile[][] buildMap = new Tile[xSize][ySize];
		// create a basic map outline
		for (int i = 0; i < xSize; i++)
			for (int j = 0; j < ySize; j++)
				buildMap[i][j] = new Tile(Tile.TileType.PLAINS, i, j);

		// create interesting terrain
		buildMap[3][5] = new Tile(Tile.TileType.MOUNTAIN, 3, 5);
		buildMap[5][2] = new Tile(Tile.TileType.MOUNTAIN, 5, 2);
		buildMap[9][4] = new Tile(Tile.TileType.MOUNTAIN, 9, 4);
		buildMap[12][11] = new Tile(Tile.TileType.MOUNTAIN, 12, 11);
		buildMap[7][13] = new Tile(Tile.TileType.MOUNTAIN, 7, 13);

		// create player 0's units
		buildMap[1][1].setUnit(new Castle(0));
		buildMap[2][1].setUnit(new MeleeUnit(1, 1, 0, 5, 1, 0));
		buildMap[1][2].setUnit(new MeleeUnit(1, 1, 0, 5, 1, 0));

		// create player 1's units
		buildMap[6][6].setUnit(new Castle(1));
		buildMap[6][5].setUnit(new MeleeUnit(1, 1, 0, 5, 1, 1));
		buildMap[5][6].setUnit(new MeleeUnit(1, 1, 0, 5, 1, 1));

		return buildMap;
	}

	/**
	 * Two-player map. Each player gets two 1-HP units. Don't use this one,
	 * either.
	 * 
	 * @return Map #1
	 */
	@Deprecated
	public static Tile[][] createTestToSucceedMap() {
		Tile[][] buildMap = new Tile[8][8];
		// create a basic map outline
		for (int i = 0; i < 8; i++)
			for (int j = 0; j < 8; j++)
				buildMap[i][j] = new Tile(Tile.TileType.PLAINS, i, j);

		// create interesting terrain
		buildMap[4][4] = new Tile(Tile.TileType.MOUNTAIN, 4, 4);
		buildMap[3][3] = new Tile(Tile.TileType.MOUNTAIN, 3, 3);

		// create player 0's units
		buildMap[1][1].setUnit(new Castle(0));
		buildMap[2][1].setUnit(new MeleeUnit(2, 2, 0, 2, 1, 0));
		buildMap[1][2].setUnit(new MeleeUnit(2, 2, 0, 2, 1, 0));

		// create player 1's units
		buildMap[6][6].setUnit(new Castle(1));
		buildMap[6][5].setUnit(new MeleeUnit(2, 1, 0, 2, 1, 1));
		buildMap[5][6].setUnit(new MeleeUnit(2, 1, 0, 2, 1, 1));

		return buildMap;
	}

	public static Tile[][] createMountainPassMap() {
		int xSize = 14;
		int ySize = 14;

		Tile[][] buildMap = new Tile[xSize][ySize];
		// create a basic map outline
		for (int i = 0; i < xSize; i++) {
			for (int j = 0; j < ySize; j++) {
				buildMap[i][j] = new Tile(Tile.TileType.PLAINS, i, j);
				if (i == j) {
					buildMap[i][j] = new Tile(Tile.TileType.MOUNTAIN, i, j);
				}
				if (i == Math.abs(13 - j)) {
					buildMap[i][j] = new Tile(Tile.TileType.MOUNTAIN, i, j);
				}
			}
		}

		// build passes
		buildMap[4][4] = new Tile(Tile.TileType.PLAINS, 4, 4);
		buildMap[9][9] = new Tile(Tile.TileType.PLAINS, 9, 9);
		buildMap[6][7] = new Tile(Tile.TileType.PLAINS, 6, 7);
		buildMap[7][6] = new Tile(Tile.TileType.PLAINS, 7, 6);

		// put castles on plains to help the AI
		buildMap[1][1] = new Tile(Tile.TileType.PLAINS, 1, 1);
		buildMap[12][12] = new Tile(Tile.TileType.PLAINS, 12, 12);

		// build units: Player 0
		buildMap[1][1].setUnit(new Castle(0));
		buildMap[2][1].setUnit(new RangedUnit(7, 1, 0, 3, 2, 0));
		buildMap[1][2].setUnit(new RangedUnit(7, 1, 0, 3, 2, 0));
		buildMap[2][2].setUnit(new RangedUnit(7, 1, 0, 3, 2, 0));
		buildMap[3][2].setUnit(new MeleeUnit(10, 2, 0, 4, 1, 0));
		buildMap[2][3].setUnit(new MeleeUnit(10, 2, 0, 4, 1, 0));

		// build units: player 1
		buildMap[12][12].setUnit(new Castle(1));
		buildMap[11][12].setUnit(new RangedUnit(7, 1, 0, 3, 2, 1));
		buildMap[12][11].setUnit(new RangedUnit(7, 1, 0, 3, 2, 1));
		buildMap[11][11].setUnit(new RangedUnit(7, 1, 0, 3, 2, 1));
		buildMap[10][11].setUnit(new MeleeUnit(10, 2, 0, 4, 1, 1));
		buildMap[11][10].setUnit(new MeleeUnit(10, 2, 0, 4, 1, 1));

		return buildMap;
	}

	/**
	 * DeltaMap: A map with two rivers.
	 */
	public static Tile[][] createDeltaMap() {
		int xSize = 14;
		int ySize = 14;

		Tile[][] buildMap = new Tile[xSize][ySize];
		// create a basic map outline
		for (int i = 0; i < xSize; i++)
			for (int j = 0; j < ySize; j++)
				buildMap[i][j] = new Tile(Tile.TileType.PLAINS, i, j);

		// create interesting terrain
		buildMap[0][0] = new Tile(Tile.TileType.RIVER, 0, 0);
		buildMap[0][1] = new Tile(Tile.TileType.RIVER, 0, 1);
		buildMap[0][2] = new Tile(Tile.TileType.RIVER, 0, 2);

		buildMap[1][0] = new Tile(Tile.TileType.RIVER, 1, 0);
		buildMap[1][1] = new Tile(Tile.TileType.RIVER, 1, 1);
		buildMap[1][2] = new Tile(Tile.TileType.RIVER, 1, 2);
		buildMap[1][3] = new Tile(Tile.TileType.RIVER, 1, 3);
		buildMap[1][4] = new Tile(Tile.TileType.RIVER, 1, 4);
		buildMap[1][5] = new Tile(Tile.TileType.RIVER, 1, 5);

		buildMap[2][0] = new Tile(Tile.TileType.RIVER, 2, 0);
		buildMap[2][1] = new Tile(Tile.TileType.RIVER, 2, 1);
		buildMap[2][2] = new Tile(Tile.TileType.RIVER, 2, 2);
		buildMap[2][6] = new Tile(Tile.TileType.RIVER, 2, 6);

		buildMap[3][1] = new Tile(Tile.TileType.RIVER, 3, 1);
		buildMap[3][2] = new Tile(Tile.TileType.RIVER, 3, 2);
		buildMap[3][7] = new Tile(Tile.TileType.RIVER, 3, 7);

		buildMap[4][2] = new Tile(Tile.TileType.RIVER, 4, 2);
		buildMap[4][8] = new Tile(Tile.TileType.RIVER, 4, 8);

		buildMap[5][3] = new Tile(Tile.TileType.RIVER, 5, 3);
		buildMap[5][4] = new Tile(Tile.TileType.RIVER, 5, 4);
		buildMap[5][8] = new Tile(Tile.TileType.RIVER, 5, 8);

		buildMap[6][4] = new Tile(Tile.TileType.RIVER, 6, 4);
		buildMap[6][8] = new Tile(Tile.TileType.RIVER, 6, 8);
		buildMap[6][9] = new Tile(Tile.TileType.RIVER, 6, 9);

		buildMap[7][4] = new Tile(Tile.TileType.RIVER, 7, 4);
		buildMap[7][9] = new Tile(Tile.TileType.RIVER, 7, 9);

		buildMap[8][4] = new Tile(Tile.TileType.RIVER, 8, 4);
		buildMap[8][9] = new Tile(Tile.TileType.RIVER, 8, 9);
		buildMap[8][5] = new Tile(Tile.TileType.RIVER, 8, 5);

		buildMap[9][5] = new Tile(Tile.TileType.RIVER, 9, 5);

		buildMap[2][5] = new Tile(Tile.TileType.MOUNTAIN, 2, 5);
		buildMap[3][6] = new Tile(Tile.TileType.MOUNTAIN, 3, 6);
		buildMap[5][2] = new Tile(Tile.TileType.MOUNTAIN, 5, 2);
		buildMap[6][3] = new Tile(Tile.TileType.MOUNTAIN, 6, 3);

		// create player 0's units
		buildMap[1][8].setUnit(new Castle(0));
		buildMap[0][8].setUnit(new MeleeUnit(7, 2, 0, 4, 1, 0));
		buildMap[2][8].setUnit(new MeleeUnit(7, 2, 0, 4, 1, 0));
		buildMap[1][7].setUnit(new MeleeUnit(7, 2, 0, 4, 1, 0));
		buildMap[1][9].setUnit(new RangedUnit(7, 1, 0, 4, 2, 0));

		// create player 1's units
		buildMap[8][1].setUnit(new Castle(1));
		buildMap[8][0].setUnit(new MeleeUnit(7, 2, 0, 4, 1, 1));
		buildMap[8][2].setUnit(new MeleeUnit(7, 2, 0, 4, 1, 1));
		buildMap[7][1].setUnit(new MeleeUnit(7, 2, 0, 4, 1, 1));
		buildMap[9][1].setUnit(new RangedUnit(7, 1, 0, 4, 2, 1));

		return buildMap;

	}
}
